
class Acceptor {
    private:
        EventLoop *_loop;
        Socket _sock;
        Channel *_channel;
        using NewConnectionCallback = std::function<void(int)>;
        /*这个回调函数功能是等获取到新连接之后， 给新连接创建Connection结构设置各项数据的接口*/
        NewConnectionCallback _new_conn_callback;
    public:
        Acceptor::Acceptor(EventLoop *loop, int port):_loop(loop)  {
            _sock.create_listener(port);
            _channel = new Channel(loop, _sock.fd());
            _channel->set_read_callback(std::bind(&Acceptor::read_handler, this));
            _channel->enable_read();
        }
        void Acceptor::set_new_conn_callback(const NewConnectionCallback &cb) {
            _new_conn_callback = cb;
        }
        /*这个函数是accept获取新连接的函数，到时候会将这个函数设置为channel的read_callback*/
        void Acceptor::read_handler() {
            int newfd = _sock.accept();
            if (newfd < 0) {
                return ;
            }
            /*_new_conn_callback是在TcpServer构造中设置的回调，主要是为newfd创建Connection对象，并完成各项参数设置*/
            return _new_conn_callback(newfd);
        }
};
